1
|
|
|
/* |
2
|
|
|
* CMS Pico - Integration of Pico within your files to create websites. |
3
|
|
|
* |
4
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
5
|
|
|
* later. See the COPYING file. |
6
|
|
|
* |
7
|
|
|
* @author Maxence Lange <[email protected]> |
8
|
|
|
* @copyright 2017 |
9
|
|
|
* @license GNU AGPL version 3 or any later version |
10
|
|
|
* |
11
|
|
|
* This program is free software: you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU Affero General Public License as |
13
|
|
|
* published by the Free Software Foundation, either version 3 of the |
14
|
|
|
* License, or (at your option) any later version. |
15
|
|
|
* |
16
|
|
|
* This program is distributed in the hope that it will be useful, |
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19
|
|
|
* GNU Affero General Public License for more details. |
20
|
|
|
* |
21
|
|
|
* You should have received a copy of the GNU Affero General Public License |
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
23
|
|
|
* |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
/** global: OC */ |
27
|
|
|
/** global: OCA */ |
28
|
|
|
/** global: pico_define */ |
29
|
|
|
/** global: pico_elements */ |
30
|
|
|
/** global: pico_nav */ |
31
|
|
|
|
32
|
|
|
var pico_result = { |
33
|
|
|
|
34
|
|
|
displayWebsites: function (list) { |
35
|
|
|
|
36
|
|
|
pico_elements.cms_pico_list_websites.emptyTable(); |
37
|
|
|
|
38
|
|
|
for (var i = 0; i < list.length; i++) { |
39
|
|
|
var tmpl = pico_nav.generateTmplWebsite(list[i]); |
40
|
|
|
pico_elements.cms_pico_list_websites.append(tmpl); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
pico_elements.cms_pico_list_websites.children('tr').each(function () { |
44
|
|
|
pico_result.interactionWebsitesDelete($(this)); |
45
|
|
|
pico_result.displayWebsitesLink($(this)); |
46
|
|
|
pico_result.displayWebsitesPath($(this)); |
47
|
|
|
pico_result.displayWebsitesTheme($(this)); |
48
|
|
|
pico_result.displayWebsitesPrivate($(this)); |
49
|
|
|
}); |
50
|
|
|
|
51
|
|
|
}, |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
displayWebsitesLink: function (div) { |
55
|
|
|
var url = div.attr('data-address'); |
56
|
|
|
div.find('TD.link').css('cursor', 'pointer').on('click', function () { |
57
|
|
|
window.open(url); |
58
|
|
|
}); |
59
|
|
|
}, |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
displayWebsitesPath: function (div) { |
63
|
|
|
var url = pico_define.nchost + pico_define.index + OC.appswebroots.files + '/?dir=' + |
64
|
|
|
div.attr('data-path'); |
65
|
|
|
div.find('TD.path').css('cursor', 'pointer').on('click', function () { |
66
|
|
|
window.open(url); |
67
|
|
|
}); |
68
|
|
|
}, |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
displayWebsitesTheme: function (div) { |
72
|
|
|
var select = div.find('SELECT.theme'); |
73
|
|
|
for (i = 0; i < pico_define.themes.length; i++) { |
|
|
|
|
74
|
|
|
var theme = pico_define.themes[i]; |
75
|
|
|
var option = $('<option>', { |
76
|
|
|
value: theme, |
77
|
|
|
text: theme |
78
|
|
|
}); |
79
|
|
|
if (theme === div.attr('data-theme')) { |
80
|
|
|
option.prop('selected', true); |
81
|
|
|
} |
82
|
|
|
select.append(option); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
select.on('change', function () { |
86
|
|
|
pico_nav.updateTheme(div.attr('data-id'), $(this).val()); |
87
|
|
|
}); |
88
|
|
|
}, |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
|
92
|
|
|
displayWebsitesPrivate: function (div) { |
93
|
|
|
div.find('INPUT.private').prop('checked', div.attr('data-private') === '1').on( |
94
|
|
|
'change', function () { |
95
|
|
|
pico_nav.updateWebsiteOption(div.attr('data-id'), 'private', |
96
|
|
|
($(this).is(':checked')) ? '1' : '0'); |
97
|
|
|
}); |
98
|
|
|
}, |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
interactionWebsitesDelete: function (div) { |
102
|
|
|
div.find('BUTTON.icon-delete').on('click', function () { |
103
|
|
|
pico_nav.deleteWebsite(div.attr('data-id'), div.attr('data-name')); |
104
|
|
|
}); |
105
|
|
|
}, |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
createNewWebsiteResult: function (result) { |
109
|
|
|
|
110
|
|
|
if (result.status === 1) { |
111
|
|
|
OCA.notification.onSuccess('Website created'); |
112
|
|
|
pico_result.displayWebsites(result.websites); |
113
|
|
|
pico_nav.resetFields(); |
114
|
|
|
return; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
OCA.notification.onFail( |
118
|
|
|
t('cms_pico', "It was not possible to create your website {name}", |
119
|
|
|
{name: result.name}) + |
120
|
|
|
': ' + ((result.error) ? result.error : t('cms_pico', 'no error message'))); |
121
|
|
|
}, |
122
|
|
|
|
123
|
|
|
|
124
|
|
|
deleteWebsiteResult: function (result) { |
125
|
|
|
|
126
|
|
|
if (result.status === 1) { |
127
|
|
|
OCA.notification.onSuccess('Website removed'); |
128
|
|
|
pico_result.displayWebsites(result.websites); |
129
|
|
|
return; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
OCA.notification.onFail( |
133
|
|
|
t('cms_pico', "It was not possible to remove the website {name}", |
134
|
|
|
{name: result.name}) + |
135
|
|
|
': ' + ((result.error) ? result.error : t('cms_pico', 'no error message'))); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
} |
139
|
|
|
; |